package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/heiyan/config"
	"net/http"
	"net/url"
)

type AdvertiseUserApiService service

type AdvertiseUserRequest struct {
	ctx        context.Context
	ApiService *AdvertiseUserApiService
	pageNum    *uint64
	pageSize   *uint64
	startDate  *string
	endDate    *string
	site       *int
	group      *int
}

type AdvertiseUserResponse struct {
	Code     *int64             `json:"code,omitempty"`
	Message  *string            `json:"message,omitempty"`
	Success  *bool              `json:"success,omitempty"`
	Redirect *bool              `json:"redirect,omitempty"`
	Data     *AdvertiseUserData `json:"data,omitempty"`
}

type AdvertiseUserData struct {
	PageNum     *uint64              `json:"pageNum,omitempty"`
	PageSize    *uint64              `json:"pageSize,omitempty"`
	TotalCount  *uint64              `json:"totalCount,omitempty"`
	TotalPage   *uint64              `json:"totalPage,omitempty"`
	HasPrePage  *bool                `json:"hasPrePage,omitempty"`
	HasNextPage *bool                `json:"hasNextPage,omitempty"`
	Items       []*AdvertiseUserItem `json:"items,omitempty"`
}

type AdvertiseUserItem struct {
	Id               *string     `json:"id,omitempty"`
	PId              *string     `json:"pid,omitempty"`
	UserId           *string     `json:"userId,omitempty"`
	BookId           *string     `json:"bookId,omitempty"`
	BookName         *string     `json:"bookName,omitempty"`
	SiteTypeValue    *int        `json:"siteTypeValue,omitempty"`
	SiteTypeDesc     *string     `json:"siteTypeDesc,omitempty"`
	GroupTypeValue   *int        `json:"groupTypeValue,omitempty"`
	GroupTypeDesc    *string     `json:"groupTypeDesc,omitempty"`
	ChannelTypeValue *int        `json:"channelTypeValue,omitempty"`
	ChannelTypeDesc  *string     `json:"channelTypeDesc,omitempty"`
	Ip               *string     `json:"ip,omitempty"`
	Ua               *string     `json:"ua,omitempty"`
	AdJson           *AdJsonInfo `json:"adJson,omitempty"`
	DyeTime          *string     `json:"dyeTime,omitempty"`
}

type AdJsonInfo struct {
	ClickId      *string `json:"clickid,omitempty"`
	PromotionId  *string `json:"promotionid,omitempty"`
	ProjectId    *string `json:"projectid,omitempty"`
	Callback     *string `json:"callback,omitempty"`
	ClickId2     *string `json:"click_id,omitempty"`
	TrackId      *string `json:"trackid,omitempty"`
	ClueToken    *string `json:"clue_token,omitempty"`
	PromotionId2 *string `json:"promotion_id,omitempty"`
	ProjectId2   *string `json:"project_id,omitempty"`
	AdvertiserId *string `json:"advertiser_id,omitempty"`
	BdVid        *string `json:"bd_vid,omitempty"`
	Imp          *string `json:"imp,omitempty"`
	AppId        *string `json:"app_id,omitempty"`
	OpenId       *string `json:"open_id,omitempty"`
	UnionId      *string `json:"union_id,omitempty"`
	Ip           *string `json:"ip,omitempty"`
	Ua           *string `json:"ua,omitempty"`
}

func (r *AdvertiseUserRequest) Pid(pid string) *AdvertiseUserRequest {
	r.ctx = context.WithValue(r.ctx, config.PId, pid)
	return r
}

func (r *AdvertiseUserRequest) Secret(secret string) *AdvertiseUserRequest {
	r.ctx = context.WithValue(r.ctx, config.Secret, secret)
	return r
}

func (r *AdvertiseUserRequest) PageNum(pageNum uint64) *AdvertiseUserRequest {
	r.pageNum = &pageNum
	return r
}

func (r *AdvertiseUserRequest) PageSize(pageSize uint64) *AdvertiseUserRequest {
	r.pageSize = &pageSize
	return r
}

func (r *AdvertiseUserRequest) StartDate(startDate string) *AdvertiseUserRequest {
	r.startDate = &startDate
	return r
}

func (r *AdvertiseUserRequest) EndDate(endDate string) *AdvertiseUserRequest {
	r.endDate = &endDate
	return r
}

func (r *AdvertiseUserRequest) Site(site int) *AdvertiseUserRequest {
	r.site = &site
	return r
}

func (r *AdvertiseUserRequest) Group(group int) *AdvertiseUserRequest {
	r.group = &group
	return r
}

func (r *AdvertiseUserRequest) Execute() (*AdvertiseUserResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *AdvertiseUserRequest) WithLog(enable bool) *AdvertiseUserRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *AdvertiseUserApiService) Get(ctx context.Context) *AdvertiseUserRequest {
	return &AdvertiseUserRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *AdvertiseUserApiService) getExecute(r *AdvertiseUserRequest) (*AdvertiseUserResponse, *http.Response, error) {
	var (
		localVarPath         = a.client.Cfg.GetBasePath() + "/spider/distribute/advertise/user"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *AdvertiseUserResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.pageNum, "PageNum"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	if ok, GenericOpenAPIError := hasReqParam(r.pageSize, "PageSize"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("pageNum", toString(r.pageNum))
	localVarQueryParams.Add("pageSize", toString(r.pageSize))

	if r.startDate != nil {
		localVarQueryParams.Add("startDate", *r.startDate)
	}

	if r.startDate != nil {
		localVarQueryParams.Add("endDate", *r.endDate)
	}

	if r.site != nil {
		localVarQueryParams.Add("site", toString(r.site))
	}

	if r.group != nil {
		localVarQueryParams.Add("group", toString(r.group))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
